package com.aboo.design.abstractfactory;

/**
 * @author louan
 * @version 1.0
 * @description: 抽象工厂模式
 * 提供一个创建一系列相关或相互依赖对象的接口，而无需指定它们具体的类。
 * @date 2024/2/6
 */
public class AbstractFactoryPattern {

    public static void main(String[] args) {
        IFactory blackFactory = new BlackFactory();
        blackFactory.createCat().miao();
        blackFactory.createDog().wang();

        IFactory whiteFactory = new WhiteFactory();
        whiteFactory.createCat().miao();
        whiteFactory.createDog().wang();
    }

}

interface ICat {
    void miao();
}

interface IDog {
    void wang();
}

class BlackCat implements ICat {

    @Override
    public void miao() {
        System.out.println("Black Cat miao");
    }
}

class WhiteCat implements ICat {

    @Override
    public void miao() {
        System.out.println("White Cat miao");
    }
}

class BlackDog implements IDog {

    @Override
    public void wang() {
        System.out.println("Black Dog wang");
    }
}

class WhiteDog implements IDog {

    @Override
    public void wang() {
        System.out.println("White Dog wang");
    }
}

interface IFactory {
    ICat createCat();
    IDog createDog();
}

class BlackFactory implements IFactory {

    @Override
    public ICat createCat() {
        return new BlackCat();
    }

    @Override
    public IDog createDog() {
        return new BlackDog();
    }
}

class WhiteFactory implements IFactory {

    @Override
    public ICat createCat() {
        return new WhiteCat();
    }

    @Override
    public IDog createDog() {
        return new WhiteDog();
    }
}
